﻿using System;
using System.Collections.Generic;
using System.Text;
using NHibernate;
using NHibernate.Expression;
using Castle.ActiveRecord;
using Castle.ActiveRecord.Queries;

namespace Mang24k99.Model.KEYW
{
    [ActiveRecord(Table = "KT_KEYW_FIXWORDS")]
    public partial class MKtKeywFixwords : ActiveRecordBase
    {
        private int _ID;

        private MKtKeywWords _MKtKeywWords;

        private MKtKeywNewstraword _MKtKeywNewstraword;
  
        private string _CompositeNO;

        private int? _ORDER;

        private int? _IsValidate;

        private DateTime? _InputTime;

        private DateTime? _ModifyTime;

        private DateTime? _DeleteTime;


        [BelongsTo("WORDS_NO")]
        public MKtKeywWords MKtKeywWords
        {
            get
            {
                return _MKtKeywWords;
            }
            set
            {
                _MKtKeywWords = value;
            }
        }
        [BelongsTo("FIXWORD_NO")]
        public MKtKeywNewstraword MKtKeywNewstraword
        {
            get
            {
                return _MKtKeywNewstraword;
            }
            set
            {
                _MKtKeywNewstraword = value;
            }
        }


        /// <summary>
        /// Gets or sets the ID.()
        /// </summary>
        /// <value>The ID.</value>
        [PrimaryKey(PrimaryKeyType.Native, "ID")]
        public int ID
        {
            get
            {
                return _ID;
            }
            set
            {
                _ID = value;
            }
        }

        /// <summary>
        /// Gets or sets the CompositeNO.()
        /// </summary>
        /// <value>The CompositeNO.</value>
        [Property("COMPOSITE_NO")]
        public string CompositeNO
        {
            get
            {
                return _CompositeNO;
            }
            set
            {
                _CompositeNO = value;
            }
        }


        /// <summary>
        /// Gets or sets the ORDER.()
        /// </summary>
        /// <value>The ORDER.</value>
        [Property("[ORDER]")]
        public int? ORDER
        {
            get
            {
                return _ORDER;
            }
            set
            {
                _ORDER = value;
            }
        }


        /// <summary>
        /// Gets or sets the IsValidate.()
        /// </summary>
        /// <value>The IsValidate.</value>
        [Property("IS_VALIDATE")]
        public int? IsValidate
        {
            get
            {
                return _IsValidate;
            }
            set
            {
                _IsValidate = value;
            }
        }


        /// <summary>
        /// Gets or sets the InputTime.()
        /// </summary>
        /// <value>The InputTime.</value>
        [Property("INPUT_TIME")]
        public DateTime? InputTime
        {
            get
            {
                return _InputTime;
            }
            set
            {
                _InputTime = value;
            }
        }


        /// <summary>
        /// Gets or sets the ModifyTime.()
        /// </summary>
        /// <value>The ModifyTime.</value>
        [Property("MODIFY_TIME")]
        public DateTime? ModifyTime
        {
            get
            {
                return _ModifyTime;
            }
            set
            {
                _ModifyTime = value;
            }
        }


        /// <summary>
        /// Gets or sets the DeleteTime.()
        /// </summary>
        /// <value>The DeleteTime.</value>
        [Property("DELETE_TIME")]
        public DateTime? DeleteTime
        {
            get
            {
                return _DeleteTime;
            }
            set
            {
                _DeleteTime = value;
            }
        }

        protected override void OnDelete()
        {
            MKtKeywFixwordsHistory mHistory = new MKtKeywFixwordsHistory();
            Common.ModelCommon.CopyObjectValues(this, mHistory);
            mHistory.WordsNO = MKtKeywWords.WordsNO;
            mHistory.FixwordNO = MKtKeywNewstraword.WordNO;
            mHistory.DeleteTime = DateTime.Now;
            mHistory.Create();
            base.OnDelete();
        }
        public static void Create(MKtKeywFixwords fixword)
        {
            fixword.Create();
        }
        /// <summary>
        /// 删除一条记录
        /// </summary>
        /// <param name="fixword"></param>
        public static void Delete(MKtKeywFixwords fixword)
        {
            fixword.Delete();
        }
        public static IList<MKtKeywFixwords> SelectAll()
        {
            return (IList<MKtKeywFixwords>)FindAll(typeof(MKtKeywFixwords));
        }
        public static MKtKeywFixwords SelectByPrimaryKey(object ID)
        {
            return (MKtKeywFixwords)FindByPrimaryKey(typeof(MKtKeywFixwords), ID);
        }
        public static IList<MKtKeywFixwords> SelectALLByProperty(string property, object value)
        {
            return (IList<MKtKeywFixwords>)FindAllByProperty(typeof(MKtKeywFixwords), property, value);
        }
        public static IList<MKtKeywFixwords> SelectALLSliced(int firstResult, int maxResult, NHibernate.Expression.DetachedCriteria criteria)
        {

            return (IList<MKtKeywFixwords>)SlicedFindAll(typeof(MKtKeywFixwords), firstResult, maxResult, criteria);
        }
        /// <summary>
        /// 根据副关键词排序号与词组编号查找记录
        /// </summary>
        /// <param name="orderNO"></param>
        /// <param name="wordsNO"></param>
        /// <returns></returns>
        public static IList<MKtKeywFixwords> SelectByOrder(object orderNO,object wordsNO)
        {
            string hql = @"from MKtKeywFixwords fixword where fixword.MKtKeywWords.WordsNO=" + wordsNO;
                    hql += @"and fixword.ORDER="+orderNO;
            SimpleQuery query = new SimpleQuery(typeof(MKtKeywFixwords),hql);
            return (IList<MKtKeywFixwords>)ExecuteQuery(query);
        }
    }
}
